package com.holyn.guofang.model.constant;

import com.holyn.guofang.model.webhttp.HttpConfigure;
import com.holyn.guofang.model.webhttp.wo.AlgorismTypeWo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Holyn on 2017/7/21.
 */
//算法类型常数
public class AlgorithmTypeConstant {

    private static final String[] TYPE_ARRAY = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"};
    private static final String[] TYPE_VALUE_ARRAY = {"图像图形", "商标名称中文", "商标名称西文", "商标图形要素",
            "注册号", "注册人名称中文", "注册人名称英文", "注册人地址中文", "注册人地址英文", "代理机构中文", "代理机构英文",
            "商品服务中文", "商品服务英文"};

    public static final String[] TYPE_ARRAY_DISTINGUISH = {"1", "2", "3"};
    public static final String[] TYPE_VALUE_ARRAY_DISTINGUISH = {"商标名称中文", "商标名称西文", "商标图形要素"};

    public static final String[] TYPE_ARRAY_SEARCH = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"};
    public static final String[] TYPE_ARRAY_SEARCH_SUBMIT_PARAMS = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"};
    public static final String[] TYPE_VALUE_ARRAY_SEARCH = {"商标名称中文", "商标名称西文", "商标图形要素",
            "注册号", "注册人名称中文", "注册人名称英文", "注册人地址中文", "注册人地址英文", "代理机构中文", "代理机构英文",
            "商品服务中文", "商品服务英文"};

    public static final String TYPE_0 = "0";//图像图形
    public static final String TYPE_1 = "1";//商标名称中文
    public static final String TYPE_2 = "2";//商标名称西文
    public static final String TYPE_3 = "3";//商标图形要素
    public static final String TYPE_4 = "4";//注册号
    public static final String TYPE_5 = "5";//注册人名称中文
    public static final String TYPE_6 = "6";//注册人名称英文
    public static final String TYPE_7 = "7";//注册人地址中文
    public static final String TYPE_8 = "8";//注册人地址英文
    public static final String TYPE_9 = "9";//代理机构中文
    public static final String TYPE_10 = "10";//代理机构英文
    public static final String TYPE_11 = "11";//商品服务中文
    public static final String TYPE_12 = "12";//商品服务英文

    public static AlgorismTypeWo getAlgorismTypeWoAll(){
        AlgorismTypeWo algorismTypeWo = new AlgorismTypeWo();
        algorismTypeWo.setErr("");
        algorismTypeWo.setStatus(HttpConfigure.STATUS_SUCCESS);

        List<AlgorismTypeWo.TypeBean> typeBeanList = new ArrayList<>();
        for (int i = 0; i <= 12; i++){
            AlgorismTypeWo.TypeBean typeBean = new AlgorismTypeWo.TypeBean();
            typeBean.setCode(TYPE_ARRAY[i]);
            typeBean.setName(TYPE_VALUE_ARRAY[i]);
            typeBeanList.add(typeBean);
        }
        algorismTypeWo.setType(typeBeanList);

        return algorismTypeWo;
    }

    public static Map<String, String> getAllTypeMap(){
        Map<String, String> typeMap = new HashMap<>();
        for (int i = 0; i < TYPE_ARRAY.length; i++ ){
            typeMap.put(TYPE_ARRAY[i], TYPE_VALUE_ARRAY[i]);
        }
        return typeMap;
    }

    public static AlgorismTypeWo getAlgorismTypeWoByTypeList(List<String> typeList){
        AlgorismTypeWo algorismTypeWo = new AlgorismTypeWo();
        algorismTypeWo.setErr("");
        algorismTypeWo.setStatus(HttpConfigure.STATUS_SUCCESS);

        Map<String, String> allTypeMap = getAllTypeMap();

        List<AlgorismTypeWo.TypeBean> typeBeanList = new ArrayList<>();
        for (String type : typeList){
            if (allTypeMap.containsKey(type)){
                AlgorismTypeWo.TypeBean typeBean = new AlgorismTypeWo.TypeBean();
                typeBean.setCode(type);
                typeBean.setName(allTypeMap.get(type));
                typeBeanList.add(typeBean);
            }
        }
        algorismTypeWo.setType(typeBeanList);
        return algorismTypeWo;
    }

    public static String getNameByType(String type){
        Map<String, String> allTypeMap = getAllTypeMap();
        if (allTypeMap.containsKey(type)){
            return  allTypeMap.get(type);
        } else {
            return "";
        }
    }

    /**
     * 在商标查询的接口，SearchMode = "0"表示"商标名称中文"，其它类推
     * 而在获取算法项目列表的接口，typeCode = "0"表示"图像图形"，typeCode = "1"表示"商标名称中文"
     * 所以，需要转换
     */
    public static String getSearchTypeParamByAlgorithmType(String typeCode){
        for (int i=0 ; i<TYPE_ARRAY_SEARCH.length; i++){
            String code = TYPE_ARRAY_SEARCH[i];
            if (typeCode.equals(code)){
                return TYPE_ARRAY_SEARCH_SUBMIT_PARAMS[i];
            }
        }
        return "";
    }

    public static String getSearchTypeByName(String typeName){
        for (int i=0 ; i<TYPE_VALUE_ARRAY_SEARCH.length; i++){
            String name = TYPE_ARRAY_SEARCH[i];
            if (typeName.equals(name)){
                return TYPE_ARRAY_SEARCH[i];
            }
        }
        return "";
    }
}
